package com.biz.facade;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.BizException;
import com.entity.enums.BillStatusEnum;
import com.entity.enums.PaymentEnum;
import com.entity.enums.ServiceItemSortEnum;
import com.entity.model.Bill;
import com.util.MFBigDecimal;
import com.util.NumberUtil;
import org.apache.commons.lang3.StringUtils;

import java.math.RoundingMode;

/**
 * Created by Administrator on 2017-09-03.
 */
public class BillLogicUtil {

    /**
     * 下单时，清除敏感数据，避免二次支付的问题
     *
     * @param bill
     */
    public static void clearDataBeforePay(Bill bill) {
            bill.setCustomerPayFee(0D);
    }

    /**
     * 更新支付信息前，检查数据
     *
     * @param bill
     * @param customerId
     * @return
     * @throws Exception
     */
    public static void checkBeforeUpdatePaymentInfo(Bill bill, Integer customerId) throws Exception {
        if (null != bill && null != customerId) {
            if (!bill.getCustomerId().equals(customerId)) {
                throw new BizException("订单不存在!");
            }
        }
        if (bill.getStatus().equals(BillStatusEnum.PAYED.getValue())
                || bill.getStatus().equals(BillStatusEnum.CHECK_OUT.getValue())
                || bill.getStatus().equals(BillStatusEnum.CHECK_IN.getValue())) {
            throw new BizException("订单已支付！");
        }

        if (bill.getStatus().equals(BillStatusEnum.CANCELED.getValue())) {
            throw new BizException("订单已过期!");
        }

        if (bill.getStatus().equals(BillStatusEnum.PAYED.getValue())) {
            throw new BizException("订单正在处理中, 不要重复支付!");
        }
    }



    public static boolean isPayed(Integer payStatus) {
        if (BillStatusEnum.PAYED.getValue() == payStatus.intValue()
                || BillStatusEnum.CHECK_IN.getValue() == payStatus.intValue()
                || BillStatusEnum.CHECK_OUT.getValue() == payStatus.intValue()) {
            return true;
        }
        return false;
    }

    public static boolean isPayedOrRefund(Integer payStatus) {
        if (BillStatusEnum.PAYED.getValue() == payStatus.intValue()
                || BillStatusEnum.CHECK_IN.getValue() == payStatus.intValue()
                || BillStatusEnum.CHECK_OUT.getValue() == payStatus.intValue()
                || BillStatusEnum.REFUNDED.getValue() == payStatus.intValue()) {
            return true;
        }
        return false;
    }
}
